package matse11.project;

import java.util.ArrayList;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;

public class SpielView extends View 
{
	private Canvas c;
	private Context context;
	private Spiel spiel;
	
	public SpielView(Context context, AttributeSet attr) 
	{
		super(context);	
	}

	public void onDraw(Canvas pc)
	{
		this.c = pc;
		Resources res = this.getContext().getResources();
		Drawable image = res.getDrawable(R.drawable.hintergrund3);
		Drawable karterueck = res.getDrawable(R.drawable.rueckseite);
		karterueck.setBounds(100,50,karterueck.getIntrinsicWidth(),karterueck.getIntrinsicHeight()-20);
		image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
		image.draw(c);
		karterueck.draw(c);
		
		if (spiel!=null)
		{		
			System.out.println("dddddddddddddddddddddddddddddddddddddddddd");
			zeichneKarten(spiel.mitspieler,c);
		}	
	}
	
	public void zeichneKarten(ArrayList<Mitspieler> mitspieler, Canvas c) 
	{
		ArrayList<Karte> dealerKarten = mitspieler.get(0).handkarten;
		ArrayList<Karte> spielerKarten = mitspieler.get(1).handkarten;
		Resources res = this.getContext().getResources();

		for (int i=0; i<spielerKarten.size(); i++)
		{
			String temp = spielerKarten.get(i).getPfad();
			String pfad = temp.substring(0, temp.length()-4);
			Drawable karte=null;
			
			if (pfad.equalsIgnoreCase("k1"))
				karte = res.getDrawable(R.drawable.k1);	 
			if (pfad.equalsIgnoreCase("k2"))
				karte = res.getDrawable(R.drawable.k2); 
			if (pfad.equalsIgnoreCase("k3"))
				karte = res.getDrawable(R.drawable.k3); 
			if (pfad.equalsIgnoreCase("k4"))	
				karte = res.getDrawable(R.drawable.k4); 
			if (pfad.equalsIgnoreCase("k5"))	
				karte = res.getDrawable(R.drawable.k5); 
			if (pfad.equalsIgnoreCase("k6"))		
				karte = res.getDrawable(R.drawable.k6); 
			if (pfad.equalsIgnoreCase("k7"))	
				karte = res.getDrawable(R.drawable.k7); 
			if (pfad.equalsIgnoreCase("k8"))
				karte = res.getDrawable(R.drawable.k8); 
			if (pfad.equalsIgnoreCase("k9"))	
				karte = res.getDrawable(R.drawable.k9); 
			if (pfad.equalsIgnoreCase("k10"))	
				karte = res.getDrawable(R.drawable.k10);	 
			if (pfad.equalsIgnoreCase("k11"))	
				karte = res.getDrawable(R.drawable.k11);	 
			if (pfad.equalsIgnoreCase("k12"))	
				karte = res.getDrawable(R.drawable.k12); 
			if (pfad.equalsIgnoreCase("k13"))	
				karte = res.getDrawable(R.drawable.k13); 
				
			if (pfad.equalsIgnoreCase("h1"))
				karte = res.getDrawable(R.drawable.h1); 
			if (pfad.equalsIgnoreCase("h2"))
				karte = res.getDrawable(R.drawable.h2); 
			if (pfad.equalsIgnoreCase("h3"))
				karte = res.getDrawable(R.drawable.h3); 
			if (pfad.equalsIgnoreCase("h4"))
				karte = res.getDrawable(R.drawable.h4); 
			if (pfad.equalsIgnoreCase("h5"))
				karte = res.getDrawable(R.drawable.h5); 
			if (pfad.equalsIgnoreCase("h6"))
				karte = res.getDrawable(R.drawable.h6); 
			if (pfad.equalsIgnoreCase("h7"))
				karte = res.getDrawable(R.drawable.h7); 
			if (pfad.equalsIgnoreCase("h8"))
				karte = res.getDrawable(R.drawable.h8); 
			if (pfad.equalsIgnoreCase("h9"))
				karte = res.getDrawable(R.drawable.h9); 
			if (pfad.equalsIgnoreCase("h10"))
				karte = res.getDrawable(R.drawable.h10); 
			if (pfad.equalsIgnoreCase("h11"))
				karte = res.getDrawable(R.drawable.h11); 
			if (pfad.equalsIgnoreCase("h12"))
				karte = res.getDrawable(R.drawable.h12);	 
			if (pfad.equalsIgnoreCase("h13"))
				karte = res.getDrawable(R.drawable.h13); 
				
			if (pfad.equalsIgnoreCase("p1"))
				karte = res.getDrawable(R.drawable.p1); 
			if (pfad.equalsIgnoreCase("p2"))
				karte = res.getDrawable(R.drawable.p2); 
			if (pfad.equalsIgnoreCase("p3"))
				karte = res.getDrawable(R.drawable.p3); 
			if (pfad.equalsIgnoreCase("p4"))
				karte = res.getDrawable(R.drawable.p4); 
			if (pfad.equalsIgnoreCase("p5"))
				karte = res.getDrawable(R.drawable.p5); 
			if (pfad.equalsIgnoreCase("p6"))
				karte = res.getDrawable(R.drawable.p6); 
			if (pfad.equalsIgnoreCase("p7"))
				karte = res.getDrawable(R.drawable.p7); 
			if (pfad.equalsIgnoreCase("p8"))
				karte = res.getDrawable(R.drawable.p8); 
			if (pfad.equalsIgnoreCase("p9"))
				karte = res.getDrawable(R.drawable.p9); 
			if (pfad.equalsIgnoreCase("p10"))
				karte = res.getDrawable(R.drawable.p10); 
			if (pfad.equalsIgnoreCase("p11"))
				karte = res.getDrawable(R.drawable.p11); 
			if (pfad.equalsIgnoreCase("p12"))
				karte = res.getDrawable(R.drawable.p12);	 
			if (pfad.equalsIgnoreCase("p13"))
				karte = res.getDrawable(R.drawable.p13); 
				
			if (pfad.equalsIgnoreCase("kr1"))	
				karte = res.getDrawable(R.drawable.kr1); 
			if (pfad.equalsIgnoreCase("kr2"))
				karte = res.getDrawable(R.drawable.kr2); 
			if (pfad.equalsIgnoreCase("kr3"))
				karte = res.getDrawable(R.drawable.kr3); 
			if (pfad.equalsIgnoreCase("kr4"))
				karte = res.getDrawable(R.drawable.kr4); 
			if (pfad.equalsIgnoreCase("kr5"))
				karte = res.getDrawable(R.drawable.kr5); 
			if (pfad.equalsIgnoreCase("kr6"))
				karte = res.getDrawable(R.drawable.kr6); 
			if (pfad.equalsIgnoreCase("kr7"))
				karte = res.getDrawable(R.drawable.kr7); 
			if (pfad.equalsIgnoreCase("kr8"))
				karte = res.getDrawable(R.drawable.kr8); 
			if (pfad.equalsIgnoreCase("kr9"))
				karte = res.getDrawable(R.drawable.kr9); 
			if (pfad.equalsIgnoreCase("kr10"))
				karte = res.getDrawable(R.drawable.kr10); 
			if (pfad.equalsIgnoreCase("kr11"))
				karte = res.getDrawable(R.drawable.kr11); 
			if (pfad.equalsIgnoreCase("kr12"))
				karte = res.getDrawable(R.drawable.kr12); 
			if (pfad.equalsIgnoreCase("kr13"))
				karte = res.getDrawable(R.drawable.kr13); 
				
			karte = res.getDrawable(R.drawable.rueckseite);
			System.out.println(c);
			karte.setBounds(100,50,karte.getIntrinsicWidth(),karte.getIntrinsicHeight()-20);
			karte.draw(c);
		}
		
		this.invalidate();
	}

	public void setSpiel(Spiel pSpiel)
	{
		spiel = pSpiel;
	}
	
	protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) 
	{
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
          setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight()-150);
	}

	
}
